package li.kaeppe.travel.tracker.web.bean;

import org.springframework.util.StringUtils;

public class PasswordChangeBean {

	/* **************************************************** */
	/*                      CONSTANTS                       */
	/* **************************************************** */

	/* **************************************************** */
	/*                     MEMBER FIELDS                    */
	/* **************************************************** */

	private String password = "";
	
	private String passwordConfirmation = "";
	
	private boolean newUser = true;
	
	/* **************************************************** */
	/*                      CONSTRUCTOR                     */
	/* **************************************************** */

	public PasswordChangeBean() {
		super();
	}
	
	public PasswordChangeBean(boolean newUser) {
		this();
		this.newUser = newUser;
	}
	
	/* **************************************************** */
	/*                    PUBLIC METHODS                    */
	/* **************************************************** */
	
	public boolean isPasswordValid() {
		boolean valid = true;
		
		if(this.isNewUser()) {
			valid = this.getPassword().equals(this.getPasswordConfirmation());
		} else {
			if (this.isPasswordSet()) {
				valid = this.getPassword().equals(this.getPasswordConfirmation());
			}
		}
		
		return valid;
	}
	
	public boolean isPasswordSet() {
		return StringUtils.hasText(this.getPassword());
	}
	
	/* **************************************************** */
	/*                  PROTECTED METHODS                   */
	/* **************************************************** */

	/* **************************************************** */
	/*                   PRIVATE METHODS                    */
	/* **************************************************** */

	/* **************************************************** */
	/*                  GETTERS AND SETTERS                 */
	/* **************************************************** */
	
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getPasswordConfirmation() {
		return passwordConfirmation;
	}

	public void setPasswordConfirmation(String passwordConfirmation) {
		this.passwordConfirmation = passwordConfirmation;
	}

	public boolean isNewUser() {
		return newUser;
	}

	public void setNewUser(boolean newUser) {
		this.newUser = newUser;
	}
	
}
